#include <gtk/gtk.h>
#include "gdk-pixbuf.h"
+#include "gdk-pixbuf-io.h"
+#include "gdk-pixbuf-loader.h"
#define DEFAULT_WIDTH 24
#define DEFAULT_HEIGHT 24
int found_valid = FALSE;
GdkPixbuf *pixbuf;
+ GtkObject *pixbuf_loader;
+ FILE *file;
+ gint val;
+ guchar buf;
gtk_init (&argc, &argv);
}
}
+ pixbuf_loader = gdk_pixbuf_loader_new ();
+ file = fopen ("/usr/share/pixmaps/up2date.png", "r");
+ g_assert (file != NULL);
+
+ while (TRUE) {
+ val = fgetc (file);
+ if (val == EOF)
+ break;
+ buf = (guint) val;
+ if (gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (pixbuf_loader), &buf, 1) == FALSE)
+ break;
+ }
+ fclose (file);
+
if (found_valid)
gtk_main ();
$(TIFF_LIB)
noinst_PROGRAMS = testpixbuf
+
+
DEPS = libgdk_pixbuf.la
INCLUDES = $(GLIB_CFLAGS) $(LIBART_CFLAGS) $(GTK_CFLAGS)
AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(libexecdir)\""
gdk-pixbuf.h \
gdk-pixbuf-loader.h
+noinst_HEADERS = \
+ gdk-pixbuf-io.h
+
#
# The PNG plugin.
#
*/
#include <config.h>
-#include <stdio.h>
#include <string.h>
-#include <gmodule.h>
-#include "gdk-pixbuf.h"
+#include "gdk-pixbuf-io.h"
\f
return FALSE;
}
+#if 0
static gboolean
pixbuf_check_bmp (guchar *buffer, int size)
{
}
return FALSE;
}
+#endif
-static struct {
- char *module_name;
- gboolean (* format_check) (guchar *buffer, int size);
- GModule *module;
- GdkPixbuf *(* load) (FILE *f);
- GdkPixbuf *(* load_xpm_data) (const gchar **data);
-} file_formats [] = {
+ModuleType file_formats [] = {
{ "png", pixbuf_check_png, NULL, NULL, NULL },
{ "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL },
{ "tiff", pixbuf_check_tiff, NULL, NULL, NULL },
};
static void
-image_handler_load (int idx)
+image_handler_load (ModuleType *image_module)
{
char *module_name;
char *path;
GModule *module;
void *load_sym;
- g_return_if_fail(file_formats[idx].module == NULL);
-
- module_name = g_strconcat ("pixbuf-", file_formats [idx].module_name, NULL);
+ g_return_if_fail(image_module->module == NULL);
+
+ module_name = g_strconcat ("pixbuf-", image_module->module_name, NULL);
path = g_module_build_path (PIXBUF_LIBDIR, module_name);
g_free (module_name);
return;
}
- file_formats [idx].module = module;
+ image_module->module = module;
if (g_module_symbol (module, "image_load", &load_sym))
- file_formats [idx].load = load_sym;
+ image_module->load = load_sym;
if (g_module_symbol (module, "image_load_xpm_data", &load_sym))
- file_formats [idx].load_xpm_data = load_sym;
+ image_module->load_xpm_data = load_sym;
}
\f
+ModuleType *
+gdk_pixbuf_get_module (gchar *buffer, gint size)
+{
+ gint i;
+
+ for (i = 0; file_formats [i].module_name; i++) {
+ if ((* file_formats [i].format_check) (buffer, size))
+ return &(file_formats[i]);
+ }
+ return NULL;
+}
+
GdkPixbuf *
gdk_pixbuf_new_from_file (const char *filename)
{
GdkPixbuf *pixbuf;
- gint n, i;
+ gint size;
FILE *f;
char buffer [128];
+ ModuleType *image_module;
f = fopen (filename, "r");
if (!f)
return NULL;
- n = fread (&buffer, 1, sizeof (buffer), f);
+ size = fread (&buffer, 1, sizeof (buffer), f);
- if (n == 0) {
+ if (size == 0) {
fclose (f);
return NULL;
}
- for (i = 0; file_formats [i].module_name; i++) {
- if ((* file_formats [i].format_check) (buffer, n)) {
- if (!file_formats [i].load)
- image_handler_load (i);
+ image_module = gdk_pixbuf_get_module (buffer, size);
+ if (image_module){
+ if (!image_module->load)
+ image_handler_load (image_module);
- if (!file_formats [i].load) {
- fclose (f);
- return NULL;
- }
-
- fseek (f, 0, SEEK_SET);
- pixbuf = (* file_formats [i].load) (f);
+ if (!image_module->load) {
fclose (f);
+ return NULL;
+ }
- if (pixbuf)
- g_assert (pixbuf->ref_count != 0);
+ fseek (f, 0, SEEK_SET);
+ pixbuf = (* image_module->load) (f);
+ fclose (f);
- return pixbuf;
- }
+ if (pixbuf)
+ g_assert (pixbuf->ref_count != 0);
+
+ return pixbuf;
+ } else {
+ g_warning ("Unable to find handler for file: %s", filename);
}
fclose (f);
- g_warning ("Unable to find handler for file: %s", filename);
return NULL;
}
{
GdkPixbuf *(* load_xpm_data) (const gchar **data);
GdkPixbuf *pixbuf;
-
+
if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
- image_handler_load(XPM_FILE_FORMAT_INDEX);
+ image_handler_load(&file_formats[XPM_FILE_FORMAT_INDEX]);
}
if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
return pixbuf;
}
-
+
-/* Nothing here yet */
+/* GdkPixbuf library - Io handling
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Mark Crichton <crichton@gimp.org>
+ * Miguel de Icaza <miguel@gnu.org>
+ * Federico Mena-Quintero <federico@gimp.org>
+ * Jonathan Blandford <jrb@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <gmodule.h>
+#include "gdk-pixbuf.h"
+#include <stdio.h>
+
+typedef struct _ModuleType ModuleType;
+struct _ModuleType {
+ char *module_name;
+ gboolean (* format_check) (guchar *buffer, int size);
+ GModule *module;
+ GdkPixbuf *(* load) (FILE *f);
+ GdkPixbuf *(* load_xpm_data) (const gchar **data);
+};
+
+
+ModuleType *gdk_pixbuf_get_module (gchar *buffer, gint size);
*/
#include "gdk-pixbuf-loader.h"
+#include "gdk-pixbuf-io.h"
-static GtkObjectClass *parent_class;
+static GtkObjectClass *parent_class;
static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass);
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
-static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
-static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
+static void gdk_pixbuf_loader_destroy (GtkObject *loader);
+static void gdk_pixbuf_loader_finalize (GtkObject *loader);
/* Internal data */
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
{
GdkPixbuf *pixbuf;
gboolean closed;
+ gchar buf[128];
+ gint buf_offset;
+ ModuleType *image_module;
};
GtkType
static void
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
{
- GdkPixbuf *pixbuf;
- loader->private = g_new (GdkPixbufLoaderPrivate, 1);
+ GdkPixbufLoaderPrivate *priv;
- loader->pixbuf = NULL;
- loader->closed = FALSE;
+ priv = g_new (GdkPixbufLoaderPrivate, 1);
+ loader->private = priv;
+
+ priv->pixbuf = NULL;
+ priv->closed = FALSE;
+ priv->buf_offset = 0;
}
static void
-gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader)
+gdk_pixbuf_loader_destroy (GtkObject *loader)
{
- GdkPixbufLoaderPrivate *priv;
+ GdkPixbufLoaderPrivate *priv = NULL;
- priv = loader->private;
+ priv = GDK_PIXBUF_LOADER (loader)->private;
gdk_pixbuf_unref (priv->pixbuf);
}
static void
-gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader)
+gdk_pixbuf_loader_finalize (GtkObject *loader)
{
- GdkPixbufLoaderPrivate *priv;
+ GdkPixbufLoader *load;
+ GdkPixbufLoaderPrivate *priv = NULL;
- priv = loader->private;
+ load = GTK_CHECK_CAST (loader, GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader);
+ priv = GDK_PIXBUF_LOADER (loader)->private;
g_free (priv);
}
* @loader: A loader.
* @buf: The image data.
* @count: The length of @buf in bytes.
- *
+ *
* This will load the next @size bytes of the image. It will return TRUE if the
* data was loaded successfully, and FALSE if an error occurred. In this case,
* the loader will be closed, and will not accept further writes.
- *
+ *
* Return value: Returns TRUE if the write was successful -- FALSE if the loader
* cannot parse the buf.
**/
gboolean
-gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
+gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
{
GdkPixbufLoaderPrivate *priv;
g_return_val_if_fail (loader != NULL, FALSE);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
+ g_return_val_if_fail (buf != NULL, FALSE);
+ g_return_val_if_fail (count >= 0, FALSE);
priv = loader->private;
/* we expect it's not to be closed */
g_return_val_if_fail (priv->closed == FALSE, FALSE);
+ if (priv->image_module == NULL) {
+ g_print ("buf_offset:%d:\n", priv->buf_offset);
+ memcpy (priv->buf + priv->buf_offset,
+ buf,
+ (priv->buf_offset + count) > 128 ? 128 - priv->buf_offset : count);
+ if ((priv->buf_offset + count) >= 128) {
+ priv->image_module = gdk_pixbuf_get_module (priv->buf, 128);
+ if (priv->image_module == NULL) {
+ g_print ("no module loaded. bummer\n");
+ return FALSE;
+ } else {
+ g_print ("module loaded: name is %s\n", priv->image_module->module_name);
+ }
+ } else {
+ priv->buf_offset += count;
+ }
+ }
return TRUE;
}
/**
* gdk_pixbuf_loader_get_pixbuf:
* @loader: A loader.
- *
+ *
* Gets the GdkPixbuf that the loader is currently loading. If the loader
* hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
* Any application using this function should check for this value when it is
* used. The pixbuf returned will be the same in all future calls to the
* loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
* using it.
- *
+ *
* Return value: The GdkPixbuf that the loader is loading.
**/
GdkPixbuf *
/**
* gdk_pixbuf_loader_close:
* @loader: A loader.
- *
+ *
* Tells the loader to stop accepting writes
*
**/
#ifdef __cplusplus
extern "C" {
-#pragma }
#endif
\f
-#define GDK_TYPE_PIXBUF_LOADER (gtk_pixbuf_get_type ())
-#define GDK_PIXBUF_LOADER (obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox))
-#define GDK_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HBOX, GtkHBoxClass))
-#define GDK_IS_PIXBUF_LOADER (obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HBOX))
-#define GDK_IS_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HBOX))
+#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ())
+#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader))
+#define GDK_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass))
+#define GDK_IS_PIXBUF_LOADER(obj) (GTK_CHECK_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER))
+#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER))
typedef struct _GdkPixbufLoader GdkPixbufLoader;
GtkObject object;
/* < Private > */
- gpointer data;
+ gpointer private;
};
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
\f
+GtkType gdk_pixbuf_loader_get_type (void);
GtkObject *gdk_pixbuf_loader_new (void);
-gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count);
+gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count);
GdkPixbuf *gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
image_load (FILE *f)
{
int w, h, i, j;
- guchar *pixels = NULL, *dptr;
+ guchar *pixels = NULL;
+ guchar *dptr;
guchar *lines[4]; /* Used to expand rows, via rec_outbuf_height, from the header file:
* "* Usually rec_outbuf_height will be 1 or 2, at most 4."
*/
free_buffer, NULL);
}
-GdkImage *
+gboolean
image_load_by_data (void *data, size_t count)
{
- return NULL;
+ return TRUE;
}
image_load (FILE *f)
{
TIFF *tiff;
- guchar *pixels, *tmppix;
+ guchar *pixels = NULL;
+ guchar *tmppix;
gint w, h, x, y, num_pixs, fd;
uint32 *rast, *tmp_rast;
*/
#include "gdk-pixbuf-loader.h"
+#include "gdk-pixbuf-io.h"
-static GtkObjectClass *parent_class;
+static GtkObjectClass *parent_class;
static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass);
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
-static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
-static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
+static void gdk_pixbuf_loader_destroy (GtkObject *loader);
+static void gdk_pixbuf_loader_finalize (GtkObject *loader);
/* Internal data */
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
{
GdkPixbuf *pixbuf;
gboolean closed;
+ gchar buf[128];
+ gint buf_offset;
+ ModuleType *image_module;
};
GtkType
static void
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
{
- GdkPixbuf *pixbuf;
- loader->private = g_new (GdkPixbufLoaderPrivate, 1);
+ GdkPixbufLoaderPrivate *priv;
- loader->pixbuf = NULL;
- loader->closed = FALSE;
+ priv = g_new (GdkPixbufLoaderPrivate, 1);
+ loader->private = priv;
+
+ priv->pixbuf = NULL;
+ priv->closed = FALSE;
+ priv->buf_offset = 0;
}
static void
-gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader)
+gdk_pixbuf_loader_destroy (GtkObject *loader)
{
- GdkPixbufLoaderPrivate *priv;
+ GdkPixbufLoaderPrivate *priv = NULL;
- priv = loader->private;
+ priv = GDK_PIXBUF_LOADER (loader)->private;
gdk_pixbuf_unref (priv->pixbuf);
}
static void
-gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader)
+gdk_pixbuf_loader_finalize (GtkObject *loader)
{
- GdkPixbufLoaderPrivate *priv;
+ GdkPixbufLoader *load;
+ GdkPixbufLoaderPrivate *priv = NULL;
- priv = loader->private;
+ load = GTK_CHECK_CAST (loader, GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader);
+ priv = GDK_PIXBUF_LOADER (loader)->private;
g_free (priv);
}
* @loader: A loader.
* @buf: The image data.
* @count: The length of @buf in bytes.
- *
+ *
* This will load the next @size bytes of the image. It will return TRUE if the
* data was loaded successfully, and FALSE if an error occurred. In this case,
* the loader will be closed, and will not accept further writes.
- *
+ *
* Return value: Returns TRUE if the write was successful -- FALSE if the loader
* cannot parse the buf.
**/
gboolean
-gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
+gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
{
GdkPixbufLoaderPrivate *priv;
g_return_val_if_fail (loader != NULL, FALSE);
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
+ g_return_val_if_fail (buf != NULL, FALSE);
+ g_return_val_if_fail (count >= 0, FALSE);
priv = loader->private;
/* we expect it's not to be closed */
g_return_val_if_fail (priv->closed == FALSE, FALSE);
+ if (priv->image_module == NULL) {
+ g_print ("buf_offset:%d:\n", priv->buf_offset);
+ memcpy (priv->buf + priv->buf_offset,
+ buf,
+ (priv->buf_offset + count) > 128 ? 128 - priv->buf_offset : count);
+ if ((priv->buf_offset + count) >= 128) {
+ priv->image_module = gdk_pixbuf_get_module (priv->buf, 128);
+ if (priv->image_module == NULL) {
+ g_print ("no module loaded. bummer\n");
+ return FALSE;
+ } else {
+ g_print ("module loaded: name is %s\n", priv->image_module->module_name);
+ }
+ } else {
+ priv->buf_offset += count;
+ }
+ }
return TRUE;
}
/**
* gdk_pixbuf_loader_get_pixbuf:
* @loader: A loader.
- *
+ *
* Gets the GdkPixbuf that the loader is currently loading. If the loader
* hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
* Any application using this function should check for this value when it is
* used. The pixbuf returned will be the same in all future calls to the
* loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
* using it.
- *
+ *
* Return value: The GdkPixbuf that the loader is loading.
**/
GdkPixbuf *
/**
* gdk_pixbuf_loader_close:
* @loader: A loader.
- *
+ *
* Tells the loader to stop accepting writes
*
**/
#ifdef __cplusplus
extern "C" {
-#pragma }
#endif
\f
-#define GDK_TYPE_PIXBUF_LOADER (gtk_pixbuf_get_type ())
-#define GDK_PIXBUF_LOADER (obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox))
-#define GDK_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HBOX, GtkHBoxClass))
-#define GDK_IS_PIXBUF_LOADER (obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HBOX))
-#define GDK_IS_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HBOX))
+#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ())
+#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader))
+#define GDK_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass))
+#define GDK_IS_PIXBUF_LOADER(obj) (GTK_CHECK_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER))
+#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER))
typedef struct _GdkPixbufLoader GdkPixbufLoader;
GtkObject object;
/* < Private > */
- gpointer data;
+ gpointer private;
};
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
\f
+GtkType gdk_pixbuf_loader_get_type (void);
GtkObject *gdk_pixbuf_loader_new (void);
-gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count);
+gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count);
GdkPixbuf *gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);